<script>

    // 检测一个对象是否是纯对象
    const isPlainObject = function isPlainObject(obj) {
        let prototype;
        return Object.prototype.toString.call(obj) === '[object Object]'
            && (prototype = Object.getPrototypeOf(obj),prototype === null
                || prototype == Object.getPrototypeOf({})
            )
    };

    // {}  new Object()  Object.create(null)
    console.log(isPlainObject({}));
    console.log(isPlainObject(new Object()));
    console.log(isPlainObject(Object.create(null)));
    console.log("-------------");
    function Person() { }
    let p = new Person()
    console.log(isPlainObject(new Array()));
    console.log(isPlainObject(p));

</script>














<!-- <script>
    // 检测是否为纯粹的对象

    // 阻止null进入判断
    // Object.prototype.toString.call(obj) === '[object Object]'  

    // new Object出来的，或Object.create(null)
    // (prototype = Object.getPrototypeOf(obj), prototype === null 
    //    || prototype == Object.getPrototypeOf({}))

    // 去掉|| prototype == Object.getPrototypeOf({}) 无法判断是否是new Object或{} 对象

    const isPlainObject = function isPlainObject(obj) {
        let prototype;
        return Object.prototype.toString.call(obj) === '[object Object]'
            && (prototype = Object.getPrototypeOf(obj), prototype === null
                || prototype == Object.getPrototypeOf({}))
    };

    console.log(isPlainObject({}));
    console.log(isPlainObject(new Object()));
    console.log(isPlainObject(Object.create(null)));

    console.log(isPlainObject(new Array()));

</script> -->